<?php

namespace app\modules\api\controllers;

use yii;
use ac\controllers\BasicController;
use ac\component\exception\ErrMap;
use app\models\OperationLog;


class AuthController extends BasicController
{
    
    public function init()
    {
        parent::init();
        // P(Yii::$app->session->get('loginInfo'));
        
        /*强制登录++++++*/
        // $info = [
        //             'member_id' => 1, 
        //             'loginname' => "", 
        //             'phone' => "", 
        //             'email' => "", 
        //             'nickname' => "零度 火焰", 
        //             'sex' => 0, 
        //             'signature' => "", 
        //             'headimgurl' => "https://thirdwx.qlogo.cn/mmopen/vi_32/Q0j4TwGTfTIvlkPBCImfjeqWfuAeU8RblKgdoe26IpYibJm02qvN6hBLWGC7oeMNczJycOYibV3BQ18nL6WxR3kQ/132", 
        //             'wechat_openid' => "ofX6S5V9c2tphs3a-yGIc_2xnGeY", 
        //             'add_time' => "2022-03-17 02:13:18"
        //         ];
        // Yii::$app->session->set('loginInfo', (object)$info);
        /*强制登录++++++*/

        if(Yii::$app->session->get('loginInfo') != null){
            $this->userInfo = Yii::$app->session->get('loginInfo');
        };
    }

    /*验证是否登录*/
    public function beforeAction($action)
    {
        if(!empty($this->userInfo)){
            return true;
        }
        if(!isset($errno)){
            list($errno, $errmsg) = ErrMap::getError(10007);
        }
        $args = array(
            'loginid' => 0,
            'loginname' => '',
            'back_code' => $errno,
            'back_info' => $errmsg,
        );
        if(gettype($res = OperationLog::addLog($args)) != 'boolean'){//操作日志
            Yii::$app->end($res);
        };
    }

}
